﻿using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

namespace WindowsApplication2.图形_声音_视频.exe和dll文件中提取图标
{
    public partial class Form1 : Form
    {
        OpenFileDialog dlg;

        public Form1()
        {
            InitializeComponent();
            dlg = new OpenFileDialog();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            dlg.Title = "选择文件...";
            dlg.RestoreDirectory = true;

            dlg.InitialDirectory = "C:\\Program Files\\";
            dlg.Filter = "exe files(*.exe)|*.exe|All files(*.*)|*.*";
            dlg.FilterIndex = 2;

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                this.textBox2.Text = dlg.FileName;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //ExtractIcon WindowsAppTmp = new ExtractIcon();
            Bitmap currentBitmap = ExtractIcon.GetIcon(this.textBox2.Text, false).ToBitmap();
            pictureBox1.Image = currentBitmap;

            FileCtrl.CreateDirectory("Img\\");
            string strPic = "Img\\" + Path.GetFileName(this.textBox2.Text) + ".bmp";
            currentBitmap.Save(strPic);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Process.Start("Img\\");
        }
    }
}